home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / knowhow4 / memory.txt < prev    next >
Text File  |  1994-10-22  |  3KB  |  53 lines

  1. /*
  2. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  3. ░░░░░░░░░░░░░░░░░░░░░░░ Memory control and debugging tools ░░░░░░░░░░░░░░░░░░
  4. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  5.  
  6. Memory errors are the most unpleasant. Debugger, IDE and program itself
  7. works in this situation in the same manner. They hang up the computer.
  8. KNOW-HOW contain the solution of this problem, really - two solutions.
  9.  
  10. First is the HCHECK.CPP (heap check) file. It works using #pragma directive,
  11. and does not require any modifications in your program. If you include it to
  12. project, it works, if not - it does not. After program termination this code
  13. outputs heap info:
  14. ▐ before: 6200, after: 1500
  15. This mean, that you have forget to call some destructor, free some memory
  16. close graphics or do something like that. "before" MUST be equial to "after".
  17. ▐ heapcheck: -1
  18. This line reports that you have destroy your heap, for example, call the
  19. destructor two times for the same structure. heapcheck MUST be 2.
  20.  
  21. Second tool is much more powerfull. It is FARHEAPD.LIB file (source codes
  22. included). To use it, for example, from IDE, you should include it to project,
  23. compile the program with debug information, then go to DOS Shell (Alt-F, D),
  24. switch on the printer, and type in DOS prompt line:
  25. ▐ >set debug=prn
  26. ▐ >program name
  27. The program will work in the usual manner, but printer will print all
  28. memory allocations, deallocations and results of these operations. Usint this
  29. listing you could find line, where result become <<heap error>> exept of
  30. <<OK>>.
  31. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  32. Taking into account that program could be extremely large, and listing - too,
  33. I include additional tool to interprete this listing (MINFO.EXE). Instead
  34. of endless listing like
  35. .......
  36. debugging C memory management:     malloc 7EA3:0004 for 80 bytes
  37. debugging C memory management:     malloc 7EA9:0004 for 80 bytes
  38. debugging C memory management:     malloc 7EAF:0004 for 4096 bytes
  39. debugging C memory management:     malloc 7FB0:0004 for 38 bytes
  40. debugging C memory management:     malloc 7FB3:0004 for 15 bytes
  41. debugging C memory management:     malloc 7FB5:0004 for 512 bytes
  42. debugging C memory management:       free 7FB5:0004
  43. debugging C memory management:     malloc 7FB5:0004 for 51 bytes
  44. debugging C memory management:     malloc 7FB9:0004 for 1 bytes
  45. debugging C memory management:     malloc 7FBA:0004 for 74 bytes
  46. .......... (total 1 Mbyte )
  47. user get:
  48. Level 1 >(  440) WARNING! Free without Malloc at pointer  0000:0000
  49. Level 1 >(  441) WARNING! Free without Malloc at pointer  0000:0000
  50. Level 1 >(  442) WARNING! Free without Malloc at pointer  0000:0000
  51. Level 1 >(  443) WARNING! Free without Malloc at pointer  0000:0000
  52. (total 4 lines)
  53.